import request from '@/utils/request'
import type { IResData } from './userAPI'

export interface IProductListReqParams {
  count: number
  limitNum: number
  search: string
  category: string
}
export interface IProduct {
  proname: string
  proid: string
  stock: number
  sales: number
  originprice: number
  category: string
  desc: string
  imgs: string[]
}
/*
  商品列表请求1
*/
export const productLIstRequest = (paramsObj: IProductListReqParams) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<IProduct[]>>({
    url: '/admin/pro/list',
    method: 'get',
    params: paramsObj,
  })
}

export const productCateLIstRequest = () => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<string[]>>({
    url: '/admin/pro/getCategory',
    method: 'get',
  })
}

export const productAddRequest = (body: IProduct) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<string[]>>({
    url: '/admin/pro/product',
    method: 'post',
    data: body,
  })
}
